Powershell Core 6.1 Cookbook by Jan-Hendrik Peters

Powershell Core 6.1 Cookbook by Jan-Hendrik Peters

Author:Jan-Hendrik Peters [Jan-Hendrik Peters]
Language: eng
Format: epub
Tags: COM088000 - COMPUTERS / System Administration / General, COM046000 - COMPUTERS / Operating Systems / General, COM005030 - COMPUTERS / Enterprise Applications / Business Intelligence Tools
Publisher: Packt
Published: 2019-04-18T08:11:41+00:00


Get-Service -Name $Name

After registering your new service, you could create another new cmdlet or use:

systemctl start polaris

How it works...

Unfortunately, the System.Service.ServiceController class that the Service cmdlets use is Windows-only. However, PowerShell Core still makes your life a lot easier, and the migration from Windows to Linux a lot more bearable, by allowing you to create your own custom cmdlets.

Again, as Linux is predominantly string-based, we are using regular expressions to parse the output of the Linux commands and simply convert them to proper objects. Observe how the match operator is used here—the $Matches variable is cloned, group 0 is removed and the resulting hash table is used as the parameter for your new object.

This recipe showed you how to use functions to create reusable code that wraps around operating system functionality. It is often necessary to extend existing functions, or create new ones in PowerShell, if nothing suitable exists. Reusable code such as Get-Service and New-Service can help you be productive on Windows and Linux.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.